﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VirtualTournaments.Business.Tournaments
{
    public class MatchWithPenaltiesResult : MatchResult
    {
        private byte _localPenaltyGoals;
        private byte _visitorPenaltyGoals;

        public MatchWithPenaltiesResult (Team local, Team visitor, byte localGoals, byte visitorGoals, byte localPenaltyGoals, byte visitorPenaltyGoals) : base (local, visitor, localGoals, visitorGoals)
        {
            LocalPenaltyGoals = localPenaltyGoals;
            VisitorPenaltyGoals = visitorPenaltyGoals;
        }

        public MatchWithPenaltiesResult(MatchResult result, byte localPenaltyGoals, byte visitorPenaltyGoals)
            : base(result.Local, result.Visitor, result.LocalGoals, result.VisitorGoals)
        {
            LocalPenaltyGoals = localPenaltyGoals;
            VisitorPenaltyGoals = visitorPenaltyGoals;
        }

        public byte LocalPenaltyGoals
        {
            get { return _localPenaltyGoals; }
            protected set { _localPenaltyGoals = value; }
        }

        public byte VisitorPenaltyGoals
        {
            get { return _visitorPenaltyGoals; }
            protected set { _visitorPenaltyGoals = value; }
        }

        public override Team GetWinner()
        {
            Team ret = base.GetWinner();
            if (ret == null)
            {
                if (LocalPenaltyGoals > VisitorPenaltyGoals)
                    ret = Local;
                else
                    ret = Visitor;
             }
             return ret;
        }

        public override Team GetLoser()
        {
            Team ret = base.GetLoser();
            if (ret == null)
            {
                if (LocalPenaltyGoals < VisitorPenaltyGoals)
                    ret = Local;
                else
                    ret = Visitor;
            }
            return ret;
        }

        public override string ToString()
        {
            return String.Concat(Local.Name, " ", LocalGoals, "(", LocalPenaltyGoals, ")", " - ", Visitor.Name, " ", VisitorGoals, "(", VisitorPenaltyGoals, ")");
        }

    }
}
